package com.ztjy.sys.biz.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ztjy.bean.Dept;
import com.ztjy.sys.biz.DeptBiz;
import com.ztjy.sys.dao.DeptDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeptBizImpl implements DeptBiz {
    @Autowired
    private DeptDao ddao;

    @Override
    public PageInfo<Dept> findAllPage(Dept dept, Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        List<Dept> deptList = ddao.selectAllDept(dept);
        PageInfo<Dept> pageInfo = new PageInfo<Dept>(deptList);
        return pageInfo;
    }

    @Override
    public Dept findDeptById(Integer id) {
        return ddao.findDeptById(id);
    }

    @Override
    public boolean addDept(Dept dept) {
        boolean flag = false;
        try {
            flag = ddao.insertSelective(dept);
        } catch (Exception e) {
            e.printStackTrace();
            flag = false;
        }
        return flag;
    }

    @Override
    public boolean updateDept(Dept dept) {
        boolean flag = false;
        try {
            flag = ddao.updateByPrimaryKeySelective(dept);
        }catch (Exception e){
            e.printStackTrace();
            flag=false;
        }
        return flag;
    }
}
